#include "PlayState.h"

PlayState::PlayState(GameContext& gameC)
	: GameState(gameC)
{
}
PlayState::~PlayState()
{
}
void PlayState::Load()
{
	mMap.Load("level01.txt", "texturepack01.txt");
	SVector2 initPos(100,100);
	mPikachu.Load();
	mPikachu.SetPosition(initPos);
	
	char levelName[256];
	char textureName[256];
	sprintf_s(levelName, 256, "level0%d.txt", mGameContext.GetLevel());
	sprintf_s(textureName, 256, "Texturepack0%d.txt", mGameContext.GetLevel());

}
void PlayState::Unload()
{
	mMap.Unload();
	mPikachu.Unload();
}
NextStates PlayState::Update(float deltaTime)
{
	mPikachu.Update(deltaTime, mMap);
	NextStates nextState = None;
	if(Input_IsKeyPressed(Keys::ESCAPE))
	{
		nextState = Frontend;
	}
	return nextState;
}
void PlayState::Render()
{
	const int kWinWidth = IniFile_GetInt("WinWidth",800);
	const int kWinHeight = IniFile_GetInt("WinHeight",800);

	SVector2 viewTarget = mPikachu.GetPosition();
	SVector2 viewOffset;
	viewOffset.x = viewTarget.x - (kWinWidth*0.5f);
	viewOffset.y = viewTarget.y - (kWinHeight*0.5f);

	SVector2 limit;
	limit.x = (float)mMap.getWidth() - kWinWidth;
	limit.y = (float)mMap.getHeight() - kWinHeight;

	viewOffset.x = Clamp(viewOffset.x, 0.0f, limit.x);
	viewOffset.y = Clamp(viewOffset.y, 0.0f, limit.y);

	mMap.RenderIsometric(viewOffset);
	mPikachu.Render(viewOffset);
}